package com.sso.service.impl;

import com.sso.cache.RedisClientTemplate;
import com.sso.mapper.UserMapper;
import com.sso.model.Account;
import com.sso.service.SsoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yangjianbo on 2016/10/10.
 */

@Service
public class SsoServiceImpl implements SsoService {


    @Autowired
    private UserMapper userMapper;

    @Override
    public String login(String username, String password) {
        Account account=this.selectUser(username);
        if(account==null){
            throw new RuntimeException("用户不存在!");
        }else if("0".equals(account.getStatus())){
            throw new RuntimeException("用户未激活!");
        }else if("2".equals(account.getStatus())){
            throw new RuntimeException("用户被锁定!");
        }else if(account.getPassword().equals(password)){
            return account.getId();
        }else {
            throw new RuntimeException("用户名和密码不匹配!");
        }
    }

    @Override
    public Account selectUser(String username) {

        return userMapper.selectByUser(username);
    }
}
